# -*- coding: utf-8 -*-
from DBUtils.PooledDB import PooledDB
import pymysql

DBCS = {'mysql': pymysql}


class DBPool(object):
    """
    数据库连接池
    """

    def __init__(self):
        """
        初始化
        """
        self.config = None
        self.pool = None

    def init_pool(self, **kwargs):
        """
        根据连接配置初始化连接池配置信息
        :param kwargs: 配置
        :return:
        """
        self.config = kwargs
        creator = DBCS.get(kwargs.get('engine', 'mysql'), pymysql)
        self.pool = PooledDB(creator, 5, **kwargs)

    def get_conn(self):
        return self.pool.connection()

# 数据库连接池对象
dbpool = DBPool()

